﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WorkFlowBLL;

namespace QLCF.Forms.Reports
{
    public partial class frmViewReportBill : Form
    {       
        private DateTime fromDate = DateTime.Now;
        private DateTime toDate = DateTime.Now;
        private int AdminID=-1;
        private string fullName = "Tất cả";
        public frmViewReportBill()
        {
            InitializeComponent();
        }
        public frmViewReportBill(DateTime fDate, DateTime tDate, int adminId)
        {
            InitializeComponent();
            fromDate = fDate;
            toDate = tDate;
            AdminID = adminId;
            CtrAdmin ctra=new CtrAdmin();
            if (AdminID > 0)
                fullName = ctra.GetInfoAdminByAdminID(AdminID).FullName;
        }
        private void frmViewReportBill_Load(object sender, EventArgs e)
        {
            string strRPSource = string.Empty;
            CtrProduct ctrp = new CtrProduct();
            long? sumMoneyAll = 0;
            long? priceServicesAll = 0;
            long? promotionMoneyAll = 0;
            long? totalMoneyAll = 0;
            var items = ctrp.GetBillReport(fromDate, toDate,
                AdminID,
                ref sumMoneyAll, ref priceServicesAll, ref promotionMoneyAll, ref totalMoneyAll);
            reportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
            reportViewer1.LocalReport.ReportEmbeddedResource = "QLCF.Reports.rptBillAll.rdlc";

            reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("prmDate", "Từ "+fromDate.ToString("dd/MM/yyyy") +" đến "+ toDate.ToString("dd/MM/yyyy")));
            reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("prmFullName","Người dùng: " +fullName));
            reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("prmTotalRecord", items.Count.ToString()));
            reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("prmSumMoney", (sumMoneyAll ?? 0) == 0 ? "0 VNĐ" : (sumMoneyAll ?? 0).ToString("0,0") + " VNĐ"));
            reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("prmPriceServices", (priceServicesAll ?? 0)==0?"0 VNĐ":(priceServicesAll ?? 0).ToString("0,0") + " VNĐ"));
            reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("prmPromotionMoney", (promotionMoneyAll ?? 0) == 0 ? "0 VNĐ" : (promotionMoneyAll ?? 0).ToString("0,0") + " VNĐ"));
            reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("prmTotalMoney", (totalMoneyAll ?? 0) == 0 ? "0 VNĐ" : (totalMoneyAll ?? 0).ToString("0,0") + " VNĐ"));

            reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("ReportBill", items));
            reportViewer1.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.PageWidth;
            reportViewer1.ZoomPercent = 100;
            reportViewer1.RefreshReport();
        }
    }
}
